import java.net.URI;
import java.net.URISyntaxException;

public class URItest {
    public static void main(String[] args) throws URISyntaxException {
        URI a=new URI("http://localhost/api/1234?x=1&v3=4");
        String ins="127.0.0.1:8080";
        String so=a.toString();
        int x=so.indexOf(a.getHost());
        String ss=so.substring(0,x)+ins+so.substring(x+a.getHost().length());
        URI b=URI.create(ss);
        System.out.println(b);
    }
}
